﻿using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class MsgPanel : BasePanel
{

	public Image iconImage;

	public Text msgText;


	private Sprite _successSprite;

	private Sprite _infoSprite;

	private Sprite _failSprite;
	
	
	public void SyncShow(string type,string content)
	{
		switch (type)
		{
			case "success":
				iconImage.sprite = _successSprite; 
				break;
			
			case "info":
				iconImage.sprite = _infoSprite;
				break;
			case "fail":
				iconImage.sprite = _failSprite;
				break;
			
		}

		msgText.text = content;
		//启用延时关闭
		Invoke("AutoHide",3);

	}


	private void Awake()
	{
		//初始化3个图标文件
		_successSprite = Resources.Load<Sprite>("Image/SuccessIcon");
		_failSprite = Resources.Load<Sprite>("Image/FailIcon");
		_infoSprite = Resources.Load<Sprite>("Image/InfoIcon");


	}


	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	private void AutoHide()
	{
		UnityFacade.Instance.UiManager.PopPanel();
	}
	
	public override void OnEnter()
	{
		if (!this.gameObject.activeSelf)
		{
			this.gameObject.SetActive(true);
		}
		
		//下滑动画
		transform.DOMoveY(4.6f, 1);
	}

	public override void OnPause()
	{
		
	}

	public override void OnResume()
	{
		
	}

	public override void OnExit()
	{
		transform.DOMoveY(6, 1).OnComplete(delegate { this.gameObject.SetActive(false); } );
	}
}
